package riteh.eventNetwork.client;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

public class ActivityTabs extends TabActivity {
	
	private Intent intentHome, intentProfile, intentCircles;
	private long userId;
	
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(C.TAG,"TABS Activity");
        setContentView(R.layout.tabs);
    
    // INSTANCIRANJE OBJEKTA
        
        userId = getIntent().getExtras().getLong("id");
        intentHome = new Intent(this, ActivityHome.class);
        intentProfile = new Intent(this, ActivityProfile.class);
        intentCircles = new Intent(this, ActivityCircles.class);
        
        intentHome.putExtra("userId", userId);
        intentProfile.putExtra("userId", userId);
        intentCircles.putExtra("userId", userId);
        
        
        // To set that activity recreates each time tab is clicked add this flag to intent
        //	.addFlag(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //intentProfile.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //intentCircles.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        final TabHost tabHost = getTabHost();

        
        tabHost.setBackgroundColor(getResources().getColor(R.color.background));

        tabHost.addTab(tabHost.newTabSpec("tabHome")
                .setIndicator("", getResources().getDrawable(R.drawable.tab_home))
                .setContent( intentHome));

        tabHost.addTab(tabHost.newTabSpec("tabProfile")
                .setIndicator("", getResources().getDrawable(R.drawable.tab_profile))
                .setContent( intentProfile));
        
        tabHost.addTab(tabHost.newTabSpec("tabCircles")
                .setIndicator("", getResources().getDrawable(R.drawable.tab_circles))
                .setContent( intentCircles));
                
        tabHost.setCurrentTab(0);
		setTabColor(tabHost);
		
        tabHost.setOnTabChangedListener (new OnTabChangeListener() {
			public void onTabChanged(String tabId) {
				setTabColor(tabHost);
			}
		});
       
    }
    
    public static void setTabColor(TabHost tabHost) {
    	
    	int tab_home = R.drawable.tab_home;
    	
    	tabHost.getTabWidget().getChildAt(0).setBackgroundResource(tab_home);
    	tabHost.getTabWidget().getChildAt(1).setBackgroundResource(tab_home);
    	tabHost.getTabWidget().getChildAt(2).setBackgroundResource(tab_home);
    	
        for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) {
            tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#22000000")); //unselected
        }
        tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#55000000"));
    }

   
}











